﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.DAO;
using ClassLibrary.Data;
using System.Data;

public partial class Admin_ucControl_ucGioiThieu : System.Web.UI.UserControl
{
    TblIntroducDAO introDAO = new TblIntroducDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadIntro();
            string id = Request.QueryString["id"];
            if (id == "" || id == null)
            {
                
            }
            else
            {
                loadDetail();
            }
        }
    }

    private void loadDetail()
    {
        string id = Request.QueryString["id"];

        DataTable dt = introDAO.GetIntroByID(Global.ConvertToInt(id));
        foreach (DataRow dr in dt.Rows)
        {
            FCKGioiThieu.Value = dr["Introduction"].ToString();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            TblIntroduc introduc = new TblIntroduc();
            introduc.Introduction = FCKGioiThieu.Value;
            string id = Request.QueryString["id"];
            if (id == null || id == "")
            {
                introDAO.InsUp_Intro(introduc, 1);
            }
            else
            {
                introduc.IDIntroduc = Global.ConvertToInt(id);
                introDAO.InsUp_Intro(introduc, 2);
            }
            flag = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        if (flag)
        {
            FCKGioiThieu.Value = string.Empty;
            LoadIntro();
        }
    }

    private void LoadIntro()
    {
        grdGioiThieu.DataSource = introDAO.GetIntro();
        grdGioiThieu.DataBind();
    }
}